/**
 * 
 */
package com.java.test.audit.mapper;

import com.java.test.audit.dto.DrawingExamineInfo;
import com.java.test.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Administrator
 *
 */
@Component
public class DrawingExamineInfoMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public int selectCount(DrawingExamineInfo info) {
		String sql = "select count(*) from examine_drawing where 1=1 ";

		if (info.getDrawingChannelValue() != 0) {
			sql += " and drawing_channelvalue='" + info.getDrawingChannelValue() + "'";
		}

		if (info.getSliceValue() != 0) {
			sql += " and slice_value ='" + info.getSliceValue() + "'";
		}

		if (info.getCodeStatus() != 0) {
			sql += " and code_status ='" + info.getCodeStatus() + "'";
		}

		if (info.getGameAccount() != null && !"".equals(info.getGameAccount())) {
			sql += " and game_account like '%" + info.getGameAccount() + "%'";
		}

		Integer i = jdbcTemplate.queryForObject(sql, Integer.class);

		return i == null ? null : i;

	}

	public List<DrawingExamineInfo> selectpageList(PageInfo<DrawingExamineInfo> page, DrawingExamineInfo info) {
		String sql = "select * from examine_drawing where 1=1 ";

		if (info.getDrawingChannelValue() != 0) {
			sql += " and drawing_channelvalue='" + info.getDrawingChannelValue() + "'";
		}

		if (info.getSliceValue() != 0) {
			sql += " and slice_value ='" + info.getSliceValue() + "'";
		}

		if (info.getCodeStatus() != 0) {
			sql += " and code_status ='" + info.getCodeStatus() + "'";
		}

		if (info.getGameAccount() != null && !"".equals(info.getGameAccount())) {
			sql += " and game_account like '%" + info.getGameAccount() + "%'";
		}
		int start = (page.getCurrentPage() - 1) * page.getPageCount();
		int limit = page.getPageCount();

		sql += "  order by drawing_time desc limit ?,?";
		List<DrawingExamineInfo> list = jdbcTemplate.query(sql, new DrawingExamineInfo(), start, limit);
		return list;
	}
	
	
	public List<DrawingExamineInfo> selectalldataList() {
		String sql = "select * from examine_drawing";
		List<DrawingExamineInfo> list = jdbcTemplate.query(sql, new DrawingExamineInfo());
		return list;
	}
	

	public DrawingExamineInfo selectExamineInfoBid(DrawingExamineInfo info) {

		String sql = "select * from examine_drawing where id=?";

		DrawingExamineInfo obj = jdbcTemplate.queryForObject(sql, new DrawingExamineInfo(), info.getId());

		return obj;

	}

	public int updateExamineInfo(int[] ids, int type) {
		String sql = "update examine_drawing set status=? where id=?";
		jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
			public int getBatchSize() {
				return ids.length;
				// 这个方法设定更新记录数，通常List里面存放的都是我们要更新的，所以返回list.size();
			}

			public void setValues(PreparedStatement ps, int i) throws SQLException {
				ps.setInt(1, type);
				ps.setInt(2, ids[i]);

			}
		});
		return 1;
	}

	public int deleteExmaineInfos(int[] ids) {
		String sql = "delete from examine_drawing where id=?";
		jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
			public int getBatchSize() {
				return ids.length;
				// 这个方法设定更新记录数，通常List里面存放的都是我们要更新的，所以返回list.size();
			}

			public void setValues(PreparedStatement ps, int i) throws SQLException {
				ps.setInt(1, ids[i]);

			}
		});
		return 1;
	}

	public List<DrawingExamineInfo> selectremitExamineList(int[] ids) {
		String id = "";
		for (int i = 0; i < ids.length; i++) {
			id += ids[i] + ",";
		}
		id = id.substring(0, id.length() - 1);

		String sql = "select * from examine_drawing where id in(" + id + ")";

		List<DrawingExamineInfo> list = jdbcTemplate.query(sql, new DrawingExamineInfo());
		return list;
	}

	/**
	 * 保存提款审核
	 * 
	 * @param info
	 * @author lijie1
	 * @date 2020/7/22 0022 17:30
	 * @return int
	 */
	public int saveDrawing(DrawingExamineInfo info) {
		String sql = "INSERT INTO examine_drawing ( "
				+ "game_account, slice_name, slice_value, drawing_amount, drawing_channelname, "
				+ "drawing_time, draw_bankaccount, STATUS, code_status,order_number,content,game_unique_id,sxf_charge,dzje_amount ) "
				+ "VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,? )";
		int i = jdbcTemplate.update(sql, info.getGameAccount(), info.getSliceName(), info.getSliceValue(),
				info.getDrawingAmount(), info.getDrawingChannelName(), info.getDrawingTime(), info.getDrawbankAccount(),
				info.getStatus(), info.getCodeStatus(), info.getOrderNumber(), info.getContent(),info.getGameUniqueId(),info.getSxfCharge(),info.getDzjeAmount());
		return i;
	}
}
